var GuestDimensionTable = {
    id: "GuestDimensionTable",
    seItem: null,
    table: null,
    layerIndex: -1
};

// 定义表头字段
GuestDimensionTable.initColumn = function () {
    var columns = [
        {field: 'selectItem', radio: true},
        {title: 'id', field: 'id', visible: false, align: 'center', valign: 'middle'},
        {title: 'customerId', field: 'customerId', visible: false, align: 'center', valign: 'middle'},
        {title: 'reservationsId', field: 'reservationsId', visible: false, align: 'center', valign: 'middle'},
        {title: '病历号', field: 'medicalRecordNumber', align: 'center', valign: 'middle', sortable: true},
        {title: '患者姓名', field: 'customerName', align: 'center', valign: 'middle', sortable: true},
        {title: '联系电话', field: 'customerPhone', align: 'center', valign: 'middle', sortable: true},
        {title: '创建人', field: 'createName', align: 'center', valign: 'middle', sortable: true},
        {title: '回访人员', field: 'revisit', align: 'center', valign: 'middle', sortable: true},
        {title: '跟踪状态', field: 'followStatus', align: 'center', valign: 'middle', sortable: true},
        {title: '消费状态', field: 'consumptionStatus', align: 'center', valign: 'middle', sortable: true},
        {title: '回访内容', field: 'remarks', align: 'center', valign: 'middle', sortable: true},
        {title: '回访结果', field: 'revisitContent', align: 'center', valign: 'middle', sortable: true},
        {title: '计划回访时间', field: 'revisitTime', align: 'center', valign: 'middle', sortable: true},
        {title: '创建时间', field: 'createTime', align: 'center', valign: 'middle', sortable: true},
        {title: '完成时间', field: 'updateTime', align: 'center', valign: 'middle', sortable: true},
        {title: '回访状态', field: 'revisitStatus', align: 'center', valign: 'middle', sortable: true,
            formatter: function (value, row, index) {
                if (value == 1) {
                    return "<span>" + "待计划" + "</span>"
                } else if (value == 2) {
                    return "<span>" + "回访完成" + "</span>"
                } else if (value == 3) {
                    return "<span>" + "回访未完成" + "</span>"
                } else if (value == 4) {
                    return "<span>" + "回访取消" + "</span>"
                }
            }
        },
        {title: '操作', field: 'id', align: 'center', valign: 'middle', width: 60,
            formatter: function (value, row, index) {

            }
        }
    ];
    return columns
};

// 判断是否选中
GuestDimensionTable.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if (selected.length == 0) {
        Feng.info("请先选中表格中的某一记录！");
        return false
    } else {
        GuestDimensionTable.seItem = selected[0];
        return true
    }
};

// 表格数据传参
GuestDimensionTable.formParams = function () {
    var queryData = {};
    queryData['guestDimensionPublic'] = $("#guestDimensionPublic", parent.document).val();
    queryData['startRevisitTime'] = $("#startRevisitTime").val();
    queryData['endRevisitTime'] = $("#endRevisitTime").val();
    return queryData
};

// 条件重置初始化
GuestDimensionTable.resetSearch = function () {
    $("#guestDimensionPublic", parent.document).val("");
    $("#startRevisitTime").val(setDateTime(new Date(), 0) + " 00:00:00");
    $("#endRevisitTime").val(setDateTime(new Date(), 0) + " 23:59:59");
    GuestDimensionTable.search();
};

// 刷新页面
GuestDimensionTable.search = function () {
    GuestDimensionTable.table.refresh({query: GuestDimensionTable.formParams()});
};

// 初始化时间
GuestDimensionTable.naturalDaySearch = function () {
    $("#startRevisitTime").val(setDateTime(new Date(), 0) + " 00:00:00");
    $("#endRevisitTime").val(setDateTime(new Date(), 0) + " 23:59:59");
    GuestDimensionTable.search();
};


$(function () {
    var defaultColunms = GuestDimensionTable.initColumn();
    var table = new BSTable(GuestDimensionTable.id, "/guest/list", defaultColunms);
    table.setPaginationType("server");
    table.setQueryParams(GuestDimensionTable.formParams());
    GuestDimensionTable.table = table.init();
    GuestDimensionTable.naturalDaySearch();
});

// 点击最上方搜索按钮根据条件赛选表格
$("#guestDimensionSearchAll", parent.document).click(function () {
    GuestDimensionTable.search();
});

// 时间回调函数 - 刷新表格
checkDate = function () {
    GuestDimensionTable.search();
};

//  打开微信聊天界面
GuestDimensionTable.openChat = function () {
    var index = layer.open({
        type: 2,
        shade: 0,
        title: '  ',
        area: ['70%', '80%'],
        fix: true,
        maxmin: true,
        isOutAnim: false,
        content: Feng.ctxPath + '/guest/guestDimension_openChat'
    });
    this.layerIndex = index;
};